package StudyCode.summary.mycollection;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class JoinsAStringArrayBasedOnTheDelimiter {
	public static void main(String[] argv) {
		String[] strings = new String[]{"1", "abc", "level", null,
				"www.tah1986.com", "asdf 123"};
		System.out.println(join(strings));
	}

	public static String join(String[] strings) {
		return join(strings, ",");
	}

	public static String join(String[] strings, String delim) {
		return join(strings, ",", false);
	}

	public static String join(String[] strings, String delim,
	                          boolean toUpper) {
		StringBuilder sb = new StringBuilder();
		boolean start = true;
		for (String string : strings) {
			if (start) {
				start = false;
			} else {
				sb.append(delim);
			}
			String appendString = toUpper ? string.toUpperCase() : string;
			sb.append(appendString);
		}
		return sb.toString();
	}
}
